package com.sweet.fourtimeoa.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sweet.fourtimeoa.mapper.CarMapper;
import com.sweet.fourtimeoa.pojo.dto.PageDto;
import com.sweet.fourtimeoa.pojo.entity.VehicleManagement;
import com.sweet.fourtimeoa.pojo.entity.VehicleUsage;
import com.sweet.fourtimeoa.pojo.vo.CarVo;
import com.sweet.fourtimeoa.pojo.vo.PageVo;
import com.sweet.fourtimeoa.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {
    @Autowired
    private CarMapper carMapper;
    @Override
    public PageVo<VehicleManagement> getAllCar(PageDto pageDto) {
        PageHelper.startPage(pageDto.getPageNum(),pageDto.getPageSize());
        Page<VehicleManagement> list = (Page<VehicleManagement>)carMapper.getAllCar();
        PageVo<VehicleManagement> pageVo = new PageVo<>();
        pageVo.setPageNum(list.getPageNum());
        pageVo.setPageSize(list.getPageSize());
        pageVo.setTotal(list.getTotal());
        pageVo.setPages(list.getPages());
        pageVo.setList(list.getResult());
        return pageVo;
    }

    @Override
    public void deleteCarById(Integer carId) {
        carMapper.deleteCarById(carId);
    }

    @Override
    public VehicleManagement getCarById(Integer carId) {
        return  carMapper.getCarById(carId);
    }

    @Override
    public void updateCar(VehicleManagement vehicleManagement) {
        carMapper.updateCar(vehicleManagement);
    }

    @Override
    public void saveCar(VehicleManagement vehicleManagement) {
        carMapper.saveCar(vehicleManagement);
    }

    @Override
    public void saveCarManage(VehicleUsage vehicleUsage) {
        carMapper.saveCarManage(vehicleUsage);
    }

    @Override
    public List<CarVo> getAllCarId() {
        return carMapper.getAllCarId();
    }
}
